package com.thd.springboot.framework.example.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.LambdaQueryWrapper;
import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.thd.springboot.framework.db.mapper.BasicMapper;
import com.thd.springboot.framework.db.service.BasicServiceImpl;
import com.thd.springboot.framework.example.entity.CgExampleEntity;
import com.thd.springboot.framework.example.mapper.CgExampleMapper;
import com.thd.springboot.framework.example.service.CgExampleService;
import com.thd.springboot.framework.utils.JacksonUtil;
import org.springframework.beans.factory.annotation.Autowired;
import org.springframework.stereotype.Service;
import org.springframework.transaction.annotation.Transactional;

import java.util.List;
import java.util.Map;

@Service
@Transactional
public class CgExampleServiceImpl extends BasicServiceImpl<CgExampleEntity> implements CgExampleService {
    @Autowired
    private CgExampleMapper cgExampleMapper;


    @Override
    public BasicMapper<CgExampleEntity> getMapper() {
        return cgExampleMapper;
    }

    public List queryAllCgExample(){
        CgExampleEntity queryCondition = new CgExampleEntity();
        return cgExampleMapper.queryListEq(null);
    };

    public CgExampleEntity queryCgExampleById(String id){
        return cgExampleMapper.queryById(id);
    };


    public List<CgExampleEntity> queryCgExampleEq(CgExampleEntity entity){
        return cgExampleMapper.queryListEq(entity);
    }

    public List<CgExampleEntity> queryCgExampleLike(CgExampleEntity entity){
        return cgExampleMapper.queryListLike(entity);
    }

    public Map<String,CgExampleEntity> queryAllToMapKey(){
        return cgExampleMapper.queryAllToMapKey();
    }





    public CgExampleEntity queryMyBatisPlusSelectOne(String id){
        QueryWrapper<CgExampleEntity> wrapper = new QueryWrapper<CgExampleEntity>();
        wrapper.eq("id",id);
        CgExampleEntity obj = cgExampleMapper.selectOne(wrapper);
        return obj;
    }
    public List<CgExampleEntity> queryByMyBatisPlusSelectList(CgExampleEntity cgExampleEntity){

        LambdaQueryWrapper<CgExampleEntity> lambdaWrapper = new LambdaQueryWrapper<CgExampleEntity>();
        lambdaWrapper.like(CgExampleEntity::getUserName,cgExampleEntity.getUserName());
        List<CgExampleEntity> l2 = cgExampleMapper.selectList(lambdaWrapper);
        System.out.println(JacksonUtil.objToJson(l2));

        return l2;

    };

}
